home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / xlisp / xlisp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  5.5 KB  |  206 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         xlisp.c
  5. * RCS:          $Header: xlisp.c,v 1.5 91/03/24 22:25:04 mayer Exp $
  6. * Description:  xlisp.c - a small implementation of lisp with object-oriented programming
  7. * Author:       David Michael Betz
  8. * Created:      
  9. * Modified:     Fri Oct  4 04:02:02 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1987, 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: xlisp.c,v 1.5 91/03/24 22:25:04 mayer Exp $";
  42.  
  43. #include "xlisp.h"
  44.  
  45. /* define the banner line string */
  46. #define BANNER    "XLISP version 2.1, Copyright (c) 1989, by David Betz"
  47.  
  48. /* global variables */
  49. jmp_buf top_level;
  50.  
  51. /* external variables */
  52. extern LVAL s_stdin,s_evalhook,s_applyhook;
  53. extern LVAL s_1plus,s_2plus,s_3plus,s_1star,s_2star,s_3star,s_minus;
  54. extern int xltrcindent;
  55. extern int xldebug;
  56. extern LVAL true;
  57. extern char buf[];
  58. extern FILE *tfp;
  59.  
  60. /* external routines */
  61. extern FILE *osaopen();
  62.  
  63. /* main - the main routine */
  64. main(argc,argv)
  65.   int argc; char *argv[];
  66. {
  67.     char *transcript;
  68.     CONTEXT cntxt;
  69.     int verbose,i;
  70.     LVAL expr;
  71.  
  72.     /* setup default argument values */
  73.     transcript = NULL;
  74.     verbose = FALSE;
  75.  
  76.     /* parse the argument list switches */
  77. #ifndef LSC
  78.     for (i = 1; i < argc; ++i)
  79.     if (argv[i][0] == '-')
  80.         switch(argv[i][1]) {
  81.         case 't':
  82.         case 'T':
  83.         transcript = &argv[i][2];
  84.         break;
  85.         case 'v':
  86.         case 'V':
  87.         verbose = TRUE;
  88.         break;
  89.         }
  90. #endif
  91.  
  92.     /* initialize and print the banner line */
  93.     osinit(BANNER);
  94.  
  95.     /* setup initialization error handler */
  96.     xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,(LVAL)1);
  97.     if (setjmp(cntxt.c_jmpbuf))
  98.     xlfatal("fatal initialization error");
  99.     if (setjmp(top_level))
  100.     xlfatal("RESTORE not allowed during initialization");
  101.  
  102.     /* initialize xlisp */
  103.     xlinit();
  104.     xlend(&cntxt);
  105.  
  106.     /* reset the error handler */
  107.     xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,true);
  108.  
  109.     /* open the transcript file */
  110.     if (transcript && (tfp = osaopen(transcript,"w")) == NULL) {
  111.     sprintf(buf,"error: can't open transcript file: %s",transcript);
  112.     stdputstr(buf);
  113.     }
  114.  
  115.     /* load "init.lsp" */
  116.     if (setjmp(cntxt.c_jmpbuf) == 0)
  117.     xlload("init.lsp",TRUE,FALSE);
  118.  
  119.     /* load any files mentioned on the command line */
  120.     if (setjmp(cntxt.c_jmpbuf) == 0)
  121.     for (i = 1; i < argc; i++)
  122.         if (argv[i][0] != '-' && !xlload(argv[i],TRUE,verbose))
  123.         xlerror("can't load file",cvstring(argv[i]));
  124.  
  125.     /* target for restore */
  126.     if (setjmp(top_level))
  127.     xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,true);
  128.  
  129.     /* protect some pointers */
  130.     xlsave1(expr);
  131.  
  132.     /* main command processing loop */
  133.     for (;;) {
  134.  
  135.     /* setup the error return */
  136.     if (setjmp(cntxt.c_jmpbuf)) {
  137.         setvalue(s_evalhook,NIL);
  138.         setvalue(s_applyhook,NIL);
  139.         xltrcindent = 0;
  140.         xldebug = 0;
  141.         xlflush();
  142.     }
  143.  
  144.     /* print a prompt */
  145.     stdputstr("> ");
  146.  
  147.     /* read an expression */
  148.     if (!xlread(getvalue(s_stdin),&expr,FALSE))
  149.         break;
  150.  
  151.     /* save the input expression */
  152.     xlrdsave(expr);
  153.  
  154.     /* evaluate the expression */
  155.     expr = xleval(expr);
  156.  
  157.     /* save the result */
  158.     xlevsave(expr);
  159.  
  160.     /* print it */
  161.     stdprint(expr);
  162.     }
  163.     xlend(&cntxt);
  164.  
  165.     /* clean up */
  166.     wrapup();
  167. }
  168.  
  169. /* xlrdsave - save the last expression returned by the reader */
  170. xlrdsave(expr)
  171.   LVAL expr;
  172. {
  173.     setvalue(s_3plus,getvalue(s_2plus));
  174.     setvalue(s_2plus,getvalue(s_1plus));
  175.     setvalue(s_1plus,getvalue(s_minus));
  176.     setvalue(s_minus,expr);
  177. }
  178.  
  179. /* xlevsave - save the last expression returned by the evaluator */
  180. xlevsave(expr)
  181.   LVAL expr;
  182. {
  183.     setvalue(s_3star,getvalue(s_2star));
  184.     setvalue(s_2star,getvalue(s_1star));
  185.     setvalue(s_1star,expr);
  186. }
  187.  
  188. /* xlfatal - print a fatal error message and exit */
  189. xlfatal(msg)
  190.   char *msg;
  191. {
  192.     oserror(msg);
  193.     wrapup();
  194. }
  195.  
  196. /* wrapup - clean up and exit to the operating system */
  197. wrapup()
  198. {
  199.     if (tfp)
  200.     osclose(tfp);
  201.     osfinish();
  202.     exit(0);
  203. }
  204.  
  205.